$(function() {
	$('#vue_vm_list div').hide();
});

var vipCard = {
	vipCardId: '',
	vipCardName: '',
	houseTypeId: '',
	price: '',
	useMonths: '',
	buckleNumber: '',
	pricePerDay: '',
	subsidization: '',
	subsidizationValue: '',
	consumptionWay: '',
	discount: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	remark: '',
	houseTypeName: '',
	subsidizationType: '',
	consumptionType: '',
	/*
	durableYears: '',
	totalPrice: ''
	*/
};

var view = {
	data: vipCard
};

var vue_vm = new Vue({
	el: '#vue_vm',
	data: view
});

findAll();

function save() {
	view.data.price = (view.data.price==''? 0: parseFloat(view.data.price));
	view.data.useMonths = (view.data.useMonths==''? 0: parseInt(view.data.useMonths));
	view.data.buckleNumber = (view.data.buckleNumber==''? 0: parseInt(view.data.buckleNumber));
	view.data.pricePerDay = (view.data.pricePerDay==''? 0: parseFloat(view.data.pricePerDay));
	view.data.discount = (view.data.discount==''? 0: parseFloat(view.data.discount));
	view.data.subsidizationType = (view.data.subsidizationType==''? 0: parseInt(view.data.subsidizationType));
	view.data.consumptionType = (view.data.consumptionType==''? 0: parseInt(view.data.consumptionType));
	/*
	view.data.durableYears = (view.data.durableYears==''? 0: parseInt(view.data.durableYears));
	view.data.totalPrice = (view.data.totalPrice==''? 0: parseFloat(view.data.totalPrice));
	*/

	save_basic(path+'/vipCard/save', {vipCard:view.data}, function() {
		alert('VIP卡保存成功');
		findAll();
	});
}

function findAll() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/vipCard/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				getSubsidizationValue:function(subsidization, subsidizationValue) {
					return subsidization=='无补助'? '': subsidizationValue;
				},
				getSubsidizationUnit:function(subsidization) {
					return subsidization=='饭卡补助'? '元': (subsidization=='包餐补助'?'天':'');
				},
				getSubsidizationText:function(subsidization, subsidizationValue) {
					return subsidization + this.getSubsidizationValue(subsidization, subsidizationValue) + this.getSubsidizationUnit(subsidization);
				},
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/vipCard/deleteBatch');
}
